#include "ItemDetailsForm.h"
#include "ui_ItemDetailsForm.h"



#include <ItemReferenceProxy.h>



ItemDetailsForm::ItemDetailsForm(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ItemDetailsForm)
{
    ui->setupUi(this);
}



ItemDetailsForm::~ItemDetailsForm()
{
    delete ui;
}



void ItemDetailsForm::setItem(Item *item, QAbstractItemModel* model)
{

    m_item = item;

    ui->nameLineEdit->setText(item->name());
    ui->descTextEdit->setPlainText(item->desc());

    ItemReferenceProxy* proxy = new ItemReferenceProxy(item, model, this);
    ui->treeView->setModel(proxy);

}



void ItemDetailsForm::on_buttonBox_clicked(QAbstractButton* button)
{

    int role = ui->buttonBox->buttonRole(button);
    switch (role)
    {
    case QDialogButtonBox::AcceptRole:
        //ui->treeView->model()->submit();
        accept();
        return;

    case QDialogButtonBox::RejectRole:
        reject();
        return;

    case QDialogButtonBox::ApplyRole:
        //ui->treeView->model()->submit();
        return;
    }

}



